package org.delphy.crimson
{
	import flash.events.MouseEvent;
	
	import mx.controls.TextInput;
	
	import org.delphy.crimson.crimsonTextInputClasses.ClearButton;
		
	public class CrimsonTextInput extends TextInput
	{
		
		private var clearButton:ClearButton;
				
		public function CrimsonTextInput()
		{
			super();
			
			styleName="crimsonTextInput";
			
			clearButton=new ClearButton();
			clearButton.width = 20;
			clearButton.height = 20;
			clearButton.addEventListener(MouseEvent.CLICK,onClearButtonClick);
		}
		
		override protected function createChildren():void{
			super.createChildren();
			
			addChild(clearButton);
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth,unscaledHeight);

			clearButton.x=unscaledWidth - clearButton.width;
			clearButton.y=unscaledHeight - clearButton.height;
		}

		private function onClearButtonClick(evt:MouseEvent):void{
			text = "";
		}
		
		protected override function measure():void{
			super.measure();
			measuredHeight = 21;
		}
		
	}
}